﻿using System;
using System.Diagnostics;
using System.Windows.Forms;

using AmazonBookLinker.Diagnostics;

namespace AmazonBookLinker
{
  public static class Context
  {
    public static string TemplateFileName;
    public static string TemplateContent;

    public static void CheckForNewVersion(bool silentDetection)
    {
      try
      {
        Version currentVersion = VersionDetector.GetCurrentVersion("AmazonBookLinker");
        if (currentVersion > AssemblyInfo.Version)
        {
          DialogResult result = MessageBox.Show("A new version is available.  Would you like to download it now?", "New version available", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);

          if (result == DialogResult.Yes)
            Process.Start(@"http://gallery.live.com/liveItemDetail.aspx?li=0aeb208a-81d1-4197-bbce-b4a42f5ec430");
        }
        else if (!silentDetection)
          MessageBox.Show("You currently have the most recent version.", "No updates necessary", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
      }
      catch (Exception ex)
      {
        PluginTracer.LogException(ex, "Checking for new version");
        PluginTracer.DisplayUnexpectedException(ex);
      }
    }
  }
}